package com.zhuhjay.common.core.config;

import cn.hutool.core.thread.ExecutorBuilder;
import cn.hutool.core.thread.ThreadUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author ZhuHJay
 * @date 2023/9/13 10:28
 */
@Configuration
public class ThreadPoolConfig {

    @Bean
    public ExecutorService executorService() {
        // 不需要核心线程，最大线程数为8，队列大小为32
        return ExecutorBuilder.create()
                .setCorePoolSize(0)
                .setMaxPoolSize(8)
                .setWorkQueue(new LinkedBlockingQueue<>(32))
                .setThreadFactory(ThreadUtil.createThreadFactory("ToolsBoot-"))
                .build();
    }

}
